package com.app.wechart.SocketUntitle;

import android.util.Log;

import org.java_websocket.WebSocket;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.drafts.Draft;
import org.java_websocket.drafts.Draft_6455;
import org.java_websocket.handshake.ServerHandshake;

import java.net.URI;
import java.nio.ByteBuffer;

public class JWebSocketClient extends org.java_websocket.client.WebSocketClient {

    private MessageUntill messageUntill;

    public JWebSocketClient(URI serverUri,MessageUntill messageUntill) {
        super(serverUri,new Draft_6455());
        this.messageUntill = messageUntill;
    }
    // 连接开启
    @Override
    public void onOpen(ServerHandshake handshakedata) {
        Log.d("TAG", "onOpen:------- "+ "连接成功");

    }

    // 接受消息
    @Override
    public void onMessage(String message) {
        this.messageUntill.onMessage(message);
        Log.d("TAG", "onMessage: -----"+message);

    }

    @Override
    public void onMessage(ByteBuffer bytes) {
        super.onMessage(bytes);
    }

    // 关闭
    @Override
    public void onClose(int code, String reason, boolean remote) {
        this.messageUntill.onClose(code,reason,remote);
        Log.d("TAG", "onClose: ------"+reason);
    }

    @Override
    public void onError(Exception ex) {
        Log.d("TAG", "onError: ----"+ex);


    }
}
